package temp;

public class 将字段声明为输入框 {

    public static void main(String[] args) {
/*

        String template = "\n" +
                "            <el-form-item label=\"${字段名称}\">\n" +
                "              <el-input :disabled=\"!params.data.edit\" v-model=\"company.${字段标志}\"></el-input>\n" +
                "            </el-form-item>\n" +
                "            ";
*/


        String template = "<el-table-column\n" +
                "                prop=\"${字段标志}\"\n" +
                "                label=\"${字段名称}\"\n" +
                "                align=\"center\">\n" +
                "              </el-table-column>";

        String s = "\n" +
                "    //产品编号\n" +
                "    private String number;\n" +
                "\n" +
                "    //产品名称\n" +
                "    private String name;\n" +
                "\n" +
                "    //建议价格\n" +
                "    private Double suggestPrice;\n" +
                "\n" +
                "    //资料清单\n" +
                "    private String resources;\n" +
                "\n" +
                "    //流程\n" +
                "    private String process;\n" +
                "\n" +
                "    //周期\n" +
                "    private String cycle;\n" +
                "\n" +
                "    //销售单位\n" +
                "    private String marketingUnit;\n" +
                "\n" +
                "    //单位成本\n" +
                "    private String unitCost;\n";

        String[] split = s.split("\n\n");

        StringBuilder builder = new StringBuilder();

        for (String block : split) {

            String[] lines = block.split("\n");

            String n = lines[0].replace("//", "").trim();

            String line = lines[1];

            line = line.trim();
            if (line.startsWith("private")) {
                line = line.replace("private ", "").replace(";", "").trim();
                String type = "";
                String name = "";
                if (line.startsWith("String")) {
                    type = "varchar(64)";
                    name = line.replace("String", "");
                } else if (line.startsWith("Integer")) {
                    type = "int(11)";
                    name = line.replace("Integer", "");
                } else if (line.startsWith("Date")) {
                    type = "datetime";
                    name = line.replace("Date", "");
                } else if (line.startsWith("Boolean")) {
                    type = "tinyint(1)";
                    name = line.replace("Boolean", "");
                }

                name = name.trim();
                /*char[] chars = name.toCharArray();

                StringBuilder b = new StringBuilder();

                for (char aChar : chars) {

                    if (aChar <= 90) {
                        b.append("_").append((char) (aChar + 32));
                    } else {
                        b.append(aChar);
                    }
                }

                name = b.toString();
*/
                //  builder.append("ALTER TABLE company ADD ").append(name).append(" ").append(type).append(";\n");

//                builder.append(template.replace("${字段名称}",n).replace("${字段标志}", name));

                builder.append("{label: '" + n + "', prop: '" + name + "', rules: [{required: true, message: '必填'}]},\n");

            }

        }

        System.out.println(builder.toString());

    }

}
